import { rectType } from '../interface/shapes'
import { _renderPaintInOrder } from '../util/style_class'
import Base from './base_class'

export default class Rect extends Base {
  type = 'Rect'
  cornerRadius: any[] = []
  constructor(data: rectType) {
    super(data)
    for (let key in data) {
      ;(this as any)[key] = (data as any)[key]
    }
  }
  async _render(ctx: any) {
    let x = this.x,
      y = this.y,
      w = this.width,
      h = this.height,
      ltr = this.cornerRadius[0],
      rtr = this.cornerRadius[1],
      rbr = this.cornerRadius[2],
      lbr = this.cornerRadius[3]

    ctx.beginPath()
    ctx.moveTo(x, y + ltr)
    ltr && ctx.arcTo(x, y, x + ltr, y, ltr)
    ctx.lineTo(x + w - rtr, y)
    rtr && ctx.arcTo(x + w, y, x + w, y + rtr, rtr)
    ctx.lineTo(x + w, y + h - rbr)
    rbr && ctx.arcTo(x + w, y + h, x + w - rbr, y + h, rbr)
    ctx.lineTo(x + lbr, y + h)
    lbr && ctx.arcTo(x, y + h, x, y + h - lbr, lbr)
    ctx.closePath()

    await this._renderStyle(ctx)
  }
}
